package protocol.transactions;

import com.netease.http.THttpRequest;

import db.manager.ManagerAccount;

import protocol.XoneProtocol;
import protocol.XoneServiceCode;
import protocol.meta.User;

public class UpdateUserTransaction extends XoneBaseTransaction {

    private User mUser;

    public UpdateUserTransaction(User user) {
        super(TRANSACTION_TYPE_UPDATE_USER);
        mUser = user;
    }

    @Override
    public void onTransact() {
        THttpRequest request = XoneProtocol.getInstance().createUpdateUserRequest(mUser);
        sendRequest(request);
    }

    @Override
    protected void onXoneTransactionSuccess(int code, Object obj) {
        ManagerAccount.getInstance().updateNickAndAvatarByUserId(mUser.userId, mUser.nickname, mUser.avatar);
        notifyMessage(XoneServiceCode.TRANSACTION_SUCCESS, null);
    }

}
